package com.woniuxy.myshop.contrloller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.myshop.entity.User;
import com.woniuxy.myshop.service.OrderService;
import com.woniuxy.myshop.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
@RequestMapping("order")
public class OrderController {

    @Autowired
    OrderService orderService ;

    @RequestMapping("/addOrder")
    @ResponseBody
    public String addOrder(int[] idArr,int aid, HttpSession session){
        User user = (User) session.getAttribute("userInfo");
        try {
            orderService.addOrder(idArr,user,aid);
            return "1" ;
        }catch (RuntimeException e) {
            e.printStackTrace();
            return "-1" ;
        }
    }
    @RequestMapping("/myorder")
    public String olist(@RequestParam(name = "now",defaultValue = "1") Integer now,
                        @RequestParam(name = "size",defaultValue = "2") Integer size,
                        String orderNum, Map map,HttpSession session){
        User user = (User) session.getAttribute("userInfo");
        map.put("orderNum",orderNum);
        //查询
        PageInfo<OrderVo>  pageInfo = orderService.queryOrderByPage(now,size,orderNum,user.getId());
        map.put("pageInfo",pageInfo);
        return "order/order" ;
    }
}
